/*
* @Author: Srain
* @Date:   2018-07-27 16:50:33
* @Last Modified by:   Srain 
* @Last Modified time: 2018-09-24 20:09:43
*/


'use strict';
require('page/common/nav/index.js');

var navSide         = require('page/common/nav-side/index.js');
var _mm             = require('util/mm.js');
var _project          = require('service/project-service.js');
var Pagination      = require('util/pagination/index.js');
var templateIndex   = require('./index.string');

var page = {
    data : {
        listParam : {     
            pageNum      : _mm.getUrlParam('pageNum')    || 1,
            pageSize     : _mm.getUrlParam('pageSize')   || 4
        }
    },
    init : function(){
        this.onLoad();
    },
    onLoad : function(){
        // 初始化左侧菜单
        navSide.init({
            name: 'user-project'
        });
        //加载我的活动信息
        this.loadList();
    },
    // 加载list数据
    loadList : function(){
        var _this       = this,
            listHtml    = '',
            listParam   = this.data.listParam,
            $panelBody   = $('.panel-body');
        $panelBody.html('<div class="loading"></div>');

        // 加载活动list
        _project.getProjectInfo(listParam, function(res){
            listHtml = _mm.renderHtml(templateIndex, {
               //原： list: res.list  --> 不显示数据
                list : res
            });
            $panelBody.html(listHtml);
            //分页
            _this.loadPagination({
                //是否有上一页
                hasPreviousPage : res.hasPreviousPage,
                prePage         : res.prePage,
                //是否有下一页
                hasNextPage     : res.hasNextPage,
                nextPage        : res.nextPage,
                //当前选择的页面
                pageNum         : res.pageNum,
                pages           : res.pages
            });
        }, function(errMsg){
            _mm.errorTips(errMsg);
        });
    },
    // 加载分页信息
    loadPagination : function(pageInfo){
        var _this = this;
        this.pagination ? '' : (this.pagination = new Pagination());
        this.pagination.render($.extend({}, pageInfo, {
            container : $('.mypagination'),
            onSelectPage : function(pageNum){
                _this.data.listParam.pageNum = pageNum;
                _this.loadList();
            }
        }));
    }
};
$(function(){
    page.init();
})